/*
 * BarraHerramientasClases.cpp
 *
 *  Created on: 27/04/2013
 *      Author: juan
 */

#include <iostream>
#include "gui/ButtonCreatorClases.h"
#include "gui/BarraDeHerramientas.h"
#include "gui/VisualComponents/clases/VisualClassComponentClase.h"
#include "gui/Tabs.h"
#include "gui/SubWindow/DrawingAreaPlusPlus.h"
#include "gui/SubWindow/Workspace.h"
#include "utils/Settings.h"


ButtonCreatorClases::ButtonCreatorClases() : tabs(NULL), buttons(NULL), images(NULL) {
}

ButtonCreatorClases::~ButtonCreatorClases() {
}

void ButtonCreatorClases::inicializar(Tabs* tabs,std::vector<Gtk::Button*>& m_buttons,std::vector<Gtk::Image*>& m_images){
    std::string buttonNames[] = { "CLASE", "ASOCIACION","AGREGACION","COMPOSICION","HERENCIA","DEPENDENCIA"};
    unsigned size = CANTIDAD_BOTONES_CLASES;

    std::string pathToImages = Settings::getInstance().getValue("ImagesPath");
    this->tabs = tabs;

    for ( unsigned i=0 ; i<size ; i++) {
        m_buttons.push_back(new Gtk::Button());
        m_images.push_back(new Gtk::Image(pathToImages + buttonNames[i] + ".png"));

        m_buttons[i]->set_label(buttonNames[i]);
        m_images[i]->show();
        m_buttons[i]->set_image_position(Gtk::POS_TOP);
        m_buttons[i]->set_image(*m_images[i]);
    }

    m_buttons[0]->signal_pressed().connect(sigc::mem_fun(this, &ButtonCreatorClases::createVisualComponent<VisualClassComponentClase>));
    m_buttons[1]->signal_pressed().connect(sigc::bind<ArrowHead::ArrowStyle>(sigc::mem_fun(this, &ButtonCreatorClases::setArrowStyle), ArrowHead::ARROW_LINE));
    m_buttons[2]->signal_pressed().connect(sigc::bind<ArrowHead::ArrowStyle>(sigc::mem_fun(this, &ButtonCreatorClases::setArrowStyle), ArrowHead::ARROW_DIAMOND));
    m_buttons[3]->signal_pressed().connect(sigc::bind<ArrowHead::ArrowStyle>(sigc::mem_fun(this, &ButtonCreatorClases::setArrowStyle), ArrowHead::ARROW_DIAMOND_FILLED));
    m_buttons[4]->signal_pressed().connect(sigc::bind<ArrowHead::ArrowStyle>(sigc::mem_fun(this, &ButtonCreatorClases::setArrowStyle), ArrowHead::ARROW_SOLID));
    m_buttons[5]->signal_pressed().connect(sigc::bind<ArrowHead::ArrowStyle>(sigc::mem_fun(this, &ButtonCreatorClases::setArrowStyle), ArrowHead::ARROW_OPEN));

    buttons = &m_buttons;
    images = &m_images;
}

template< typename T > void ButtonCreatorClases::createVisualComponent(){
    Workspace* currentWorkspace = tabs->getCurrentWorkspace();
    if ( currentWorkspace == NULL)
        return;
    HandlerCreateComponent* handler = new HandlerCreateComponent(currentWorkspace, new T(currentWorkspace->getDiagram()));
    currentWorkspace->setHandler(handler);
   for( unsigned i=0 ; i<buttons->size() ; i++){
       (*buttons)[i]->get_display()->pointer_ungrab(0);
    }
}
